#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_oddisp.info <<'%EOF%'
   cc_rsp_oddisp
   -------------
   Molecule:         HF in C2
   Wave Function:    CCS, CCSD / 6-31G**
   Test Purpose:     Dispersion coefficients for pure imaginary
                     quadratic response functions
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_oddisp.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    1  Y  X      1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_oddisp.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
.ANGMOM
.THETA
**WAVE FUNCTIONS
.TITLE
  for CCS and CCSD wavefunctions compute:
  - <<x,y,Lz>> , <<x,Lz,y>>, <<x,x,zz>> for two frequencies
  - 1. -- 7. order dispersion coefficients
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CCSD
.THRENR
 1.0d-10
.THRLEQ
 1.0d-10
.PRINT
  5
*CCQR
.OPERATOR
XDIPLEN YDIPLEN ZANGMOM
XDIPLEN ZANGMOM YDIPLEN
XDIPLEN XDIPLEN ZZTHETA
.DISPCF
  7
.STATIC
.ORFREQ
  2
0.072002781 0.1
.SHGFRE
  2
0.072002781 0.1
.EOPEFR
  2
0.072002781 0.1
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_oddisp.check
cat >>cc_rsp_oddisp.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-100.008919(8|9)." | wc -l`
CRIT2=`$GREP "Total SCF   energy:                  \-100.008919(8|9)." $log | wc -l`
CRIT3=`$GREP "Total MP2   energy:                  \-100.193662(5|6)." $log | wc -l`
CRIT4=`$GREP "Total CCSD  energy:                  \-100.1977909." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=8
ERROR[1]="ENERGIES NOT CORRECT"

# CCS freq.-dep. first hyperpolarizabilities:
CRIT1=`$GREP "XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * YDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * ZANGMOM * \(unrel.\) (\-0| \-|  | 0)\.0000 * (\-0|\-| |0)\." $log | wc -l`
CRIT2=`$GREP "XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * ZANGMOM * \(unrel.\) (\-0| \-|  | 0)\.0000 * YDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * (\-0|\-| |0)\." $log | wc -l`
CRIT3=`$GREP "XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * ZZTHETA * \(unrel.\) (\-0| \-|  | 0)\.0000 * 1.58444(0|1)" $log | wc -l`
CRIT4=`$GREP "(\-0|\-| |0)\.0000[ ]* ( |0)\.0720[ ]* ( \-|\-0)\.0720 * ( |0)\.110242" $log | wc -l`
CRIT5=`$GREP "(\-0|\-| |0)\.0000[ ]* ( |0)\.0720[ ]* ( \-|\-0)\.0720 * ( \-|\-0)\.110242" $log | wc -l`
CRIT6=`$GREP "(\-0|\-| |0)\.0000[ ]* ( |0)\.0720[ ]* ( \-|\-0)\.0720 * 1.61675(7|8)" $log | wc -l`
CRIT7=`$GREP "( \-|\-0)\.1440[ ]* ( |0)\.0720[ ]* ( |0)\.0720 * ( |0)\.360339" $log | wc -l`
CRIT8=`$GREP "( \-|\-0)\.1440[ ]* ( |0)\.0720[ ]* ( |0)\.0720 * ( |0)\.360339" $log | wc -l`
CRIT9=`$GREP "( \-|\-0)\.1440[ ]* ( |0)\.0720[ ]* ( |0)\.0720 * 1.816034" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 + $CRIT4 \+ $CRIT5 \+ $CRIT6 + $CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[2]=13
ERROR[2]="CCS FREQ.-DEP. 1. HYPERPOLARIZABILITIES NOT CORRECT"

# CCS first hyperpolarizabilities odd dispersion coefficients:
CRIT1=`$GREP "XDIPLEN      YDIPLEN      ZANGMOM  * 1    4\.50125(7|8).       1\.500419.       3\.00083(8|9)." $log | wc -l`
CRIT2=`$GREP "                                   * 3    86\.396(0|1)..       5\.7597(3|4)..       23\.0389(5|6)." $log | wc -l`
CRIT3=`$GREP "                                   * 5    1836\.22(7|8|9).       29\.1464(7|8|9).       174\.878(8|9)." $log | wc -l`
CRIT4=`$GREP "                                   * 7    38389\.2..       150\.54(5|6)..       1204\.36(7|8)." $log | wc -l`
CRIT5=`$GREP "XDIPLEN      ZANGMOM      YDIPLEN  * 1    4\.50125(7|8).      \-1\.500419.       1\.500419." $log | wc -l`
CRIT6=`$GREP "                                   * 3    86\.396(0|1)..      \-5\.7597(3|4)..       5\.7597(3|4).." $log | wc -l`
CRIT7=`$GREP "XDIPLEN      XDIPLEN      ZZTHETA  * 0    1\.58444(0|1).       1\.58444(0|1).       1\.58444(0|1)." $log | wc -l`
CRIT8=`$GREP "                                   * 2    39\.6964(0|1|2).       6\.06057(5|6|7).       16\.8179(1|2)." $log | wc -l`
CRIT9=`$GREP "                                   * 4    855\.801..       32\.4324(4|5|6).       129\.585(2|3)." $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 + $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[3]=9
ERROR[3]="CCS 1. HYPERPOLARIZABILITIES DISPERSION COEFFICIENTS NOT CORRECT"

# CCSD freq.-dep. first hyperpolarizabilities:
CRIT1=`$GREP "XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * YDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * ZANGMOM * \(unrel.\) (\-0| \-|  | 0)\.0000 * (\-0|\-| |0)\." $log | wc -l`
CRIT2=`$GREP "XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * ZANGMOM * \(unrel.\) (\-0| \-|  | 0)\.0000 * YDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * (\-0|\-| |0)\." $log | wc -l`
CRIT3=`$GREP "XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * XDIPLEN * \(unrel.\) (\-0| \-|  | 0)\.0000 * ZZTHETA * \(unrel.\) (\-0| \-|  | 0)\.0000 * 1.717869" $log | wc -l`
CRIT4=`$GREP "(\-0|\-| |0)\.0000[ ]* ( |0)\.0720[ ]* ( \-|\-0)\.0720     ( |0)\.145463" $log | wc -l`
CRIT5=`$GREP "(\-0|\-| |0)\.0000[ ]* ( |0)\.0720[ ]* ( \-|\-0)\.0720    ( \-|\-0)\.145463" $log | wc -l`
CRIT6=`$GREP "(\-0|\-| |0)\.0000[ ]* ( |0)\.0720[ ]* ( \-|\-0)\.0720      1.765741" $log | wc -l`
CRIT7=`$GREP "( \-|\-0)\.1440[ ]* ( |0)\.0720[ ]* ( |0)\.0720     ( |0)\.488792" $log | wc -l`
CRIT8=`$GREP "( \-|\-0)\.1440[ ]* ( |0)\.0720[ ]* ( |0)\.0720     ( |0)\.488792" $log | wc -l`
CRIT9=`$GREP "( \-|\-0)\.1440[ ]* ( |0)\.0720[ ]* ( |0)\.0720      2.040192" $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 + $CRIT4 \+ $CRIT5 \+ $CRIT6 + $CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[4]=13
ERROR[4]="CCSD FREQ.-DEP. 1. HYPERPOLARIZABILITIES NOT CORRECT"

# CCSD first hyperpolarizabilities odd dispersion coefficients:
CRIT1=`$GREP "XDIPLEN      YDIPLEN      ZANGMOM          1    5\.9021(0|1)..       1\.9673(69|70).       3\.9347(39|40)." $log | wc -l`
CRIT2=`$GREP "                                           3    148\.108(0|1).       9\.8738(6|7)..       39\.4954(7|8|9)." $log | wc -l`
CRIT3=`$GREP "                                           5    3833\.55..       60\.8500..       365\.100.." $log | wc -l`
CRIT4=`$GREP "                                           7    96909\.(3|4)..       380\.03(6|7)..       3040\.29.." $log | wc -l`
CRIT5=`$GREP "XDIPLEN      ZANGMOM      YDIPLEN          1    5\.9021(0|1)..      \-1\.9673(69|70).       1\.9673(69|70)." $log | wc -l`
CRIT6=`$GREP "                                           3    148\.108(0|1).      \-9\.8738(6|7)..       9\.8738(6|7).." $log | wc -l`
CRIT7=`$GREP "XDIPLEN      XDIPLEN      ZZTHETA          0    1\.717869.       1\.717869.       1\.717869." $log | wc -l`
CRIT8=`$GREP "                                           2    53\.891(1|2)..       8\.92139..       22\.48490." $log | wc -l`
CRIT9=`$GREP "                                           4    1389\.30(3|4).       58\.249(8|9)..       206\.107(8|9)." $log | wc -l`
TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 + $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9`
CTRL[5]=9
ERROR[5]="CCSD 1. HYPERPOLARIZABILITIES DISPERSION COEFFICIENTS NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
